package com.wgke.bluetooth.utils;

import android.text.TextUtils;

import androidx.core.content.ContextCompat;

import com.wgke.bluetooth.R;

import java.util.HashMap;
import java.util.Map;

public class ColorUtils {

    private static Map<String, Integer> colorMap;

    //private static int[] colors = new int[]{R.color.white_1, R.color.white_2, R.color.white_3, R.color.white_4, R.color.white_5, R.color.white_6, R.color.white_7,};
    private static int[] bgs = new int[]{R.color.btn_red, R.color.btn_blue, R.color.btn_green, R.color.btn_org, R.color.btn_purple};

    private static int index = 0;

    public static int getColor(String str) {
        if (str != null && !TextUtils.isEmpty(str.trim())) {
            String[] arr = str.split("\\s+");
            if (arr.length > 0) {
                String key = arr[0];
                if (colorMap == null) {
                    colorMap = new HashMap<>();
                }
                int resId = 0;
                Integer res = colorMap.get(key);
                if (res == null) {
                    resId = bgs[index % bgs.length];
                    colorMap.put(key, resId);
                    index++;
                } else {
                    resId = res;
                }
                return resId;
            }
        }
        return R.color.btn_red;
    }
}
